from dotenv import load_dotenv, find_dotenv
from langchain_community.chat_models import ChatZhipuAI 
from langchain_community.tools.tavily_search import TavilySearchResults

_ = load_dotenv(find_dotenv())
 
model = ChatZhipuAI(
        model="glm-4-plus",
        temperature=0.9,              
    )
#model = ChatOpenAI(model="gpt-4o")

search = TavilySearchResults()
tools = [search]


from langchain import hub
prompt = hub.pull("hwchase17/react-chat-json")

from langchain.agents import AgentExecutor, create_json_chat_agent
agent = create_json_chat_agent(model, tools, prompt)
agent_executor = AgentExecutor(
    agent=agent, tools=tools, verbose=True, handle_parsing_errors=True
)

agent_executor.invoke({"input": "什么是新型电力系统?"})
# agent_executor.invoke({"input": "请写一首关于春天的诗。"})